package cn.sciento.farm.devicemanager.gateway.downlink;

import cn.sciento.farm.devicemanager.common.constant.DeviceConstant;
import cn.sciento.farm.devicemanager.gateway.model.downlink.BaseBlockControlData;
import cn.sciento.farm.devicemanager.gateway.model.downlink.LoraWanControlData;
import cn.sciento.farm.devicemanager.gateway.model.downlink.SimpleBlockControlData;
import org.apache.commons.lang3.StringUtils;

/**
 * @author wumu
 * @version V1.0
 * @date 9/21/18
 * @time 8:51 PM
 */
public class MqttDataFactory {


    public static final String BLOCK_CONTROL = "block_control";
    public static final String SIMPLE_CONTROL = "simple_control";
    public static final String BATCH_CONTROL = "batch_control";

    private MqttDataFactory() {

    }

    private static MqttDataFactory mqttDataFactory = new MqttDataFactory();

    public static MqttDataFactory getMqttDataFactory() {
        return mqttDataFactory;
    }

    public BaseBlockControlData createData(String protocol, String type) {
        if (StringUtils.isEmpty(protocol)) {
            protocol = DeviceConstant.SIMPLE;
        }
        switch (type) {
            case BLOCK_CONTROL:
                if (protocol.equals(DeviceConstant.LORAWAN)) {
                    return LoraWanControlData.builder().build();
                } else if (protocol.equals(DeviceConstant.SIMPLE)) {
                    return SimpleBlockControlData.builder().build();
                }
                break;
            case SIMPLE_CONTROL:
                if (protocol.equals(DeviceConstant.LORAWAN)) {
                    return LoraWanControlData.builder().build();
                } else if (protocol.equals(DeviceConstant.SIMPLE)) {
                    return SimpleBlockControlData.builder().build();
                }
                break;
            case BATCH_CONTROL:
                break;
            default:
                return null;
        }
        return null;
    }
}
